276B - Little Girl and Game - CodeForces Solution


games greedy *1300

Please click on ads to support us..

Python Code:

from collections import Counter
s = input()
c = Counter(s)
even = {}
odd = {}
for key, value in c.items():
    if value % 2 == 0:
        even[key] = value
    else:
        odd[key] = value
i = 0
while True:
    if len(odd) <= 1: 
        print('First' if i % 2 == 0 else 'Second')
        break
    if even:
        key, value = even.popitem()
        odd[key] = value - 1
    else:
        key, value = odd.popitem()
        if value > 1:
            even[key] = value - 1
    i += 1

            

C++ Code:

#include<cstring>
    #define push_back pb
    #define push_front pf
    #define first F
    #define second S
    #include <bits/stdc++.h>
    #include <string>
    #define all(a) a.begin(), a.end()
    #define allr(a) a.rbegin(), a.rend()
    typedef long long ll;
    typedef unsigned long long ull;
    using namespace std;
    const ll N = 1e5;
    const ll INF =5e18;
    const ll mod = 1e9+7;
    map<ll,ll>mp;
//    map<ll,ll>mp,cnt;
//    ll gcd(ll a,ll b){
//        if(a==0 || b==0) return a+b;
//        return gcd(b,a%b);
//    }
//    ll num[N];
//    set<ll>s;
//    vector<ll>primes;
//    void seive(){
//        num[2]=2;
//        for(int i = 3;i<N;i+=2){
//            num[i]=i;
//        }
//        for(int i = 3;i*i<N;i++){
//            if(num[i]==i){
//                for(int j = i*i;j<N;j+=i){
//                    num[j]=0;
//                }
//            }
//        }
//        for(int i = 2;i<N;i++){
//            if(num[i]==i){
//                primes.pb(i);
//            }
//        }
//    }
//    bool is_prime(ll n){
//        for(int i = 2;i*i<=n;i++){
//            if(n%i==0){
//                return false;
//            }
//        }
//        return true;
//    }
    int main()
    {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
//        ll t;
//        cin>>t;
//        while(t--){
            string s;
            cin>>s;
            ll cnt[26+1]={0};
            for(int i=0;i<s.size();i++){
                cnt[s[i]-'a'+1]++;
            }
            ll od=0;
            ll ev=0;
            ll ans=0;
            for(int i = 1;i<=26;i++){
                if(cnt[i]){
                    ans++;
                }
                if(cnt[i]&1){
                    od++;
                }
                else{
                    ev++;
                }
            }
            if(od==1 || od==0 || (od&1)){
                cout<<"First"<<endl;
            }

            else{
                cout<<"Second"<<endl;
            }

//        }






        return 0;
    }


Comments

Submit
0 Comments
More Questions

e-maze-in
Bricks Game
Char Sum
Two Strings
Anagrams
Prime Number
Lexical Sorting Reloaded
1514A - Perfectly Imperfect Array
580A- Kefa and First Steps
1472B- Fair Division
996A - Hit the Lottery
MSNSADM1 Football
MATCHES Playing with Matches
HRDSEQ Hard Sequence
DRCHEF Doctor Chef
559. Maximum Depth of N-ary Tree
821. Shortest Distance to a Character
1441. Build an Array With Stack Operations
1356. Sort Integers by The Number of 1 Bits
922. Sort Array By Parity II
344. Reverse String
1047. Remove All Adjacent Duplicates In String
977. Squares of a Sorted Array
852. Peak Index in a Mountain Array
461. Hamming Distance
1748. Sum of Unique Elements
897. Increasing Order Search Tree
905. Sort Array By Parity
1351. Count Negative Numbers in a Sorted Matrix
617. Merge Two Binary Trees